

    const passport = require('koa-passport')
    const localStrategy = require('passport-local').Strategy
    const encryption = require('../lib/encryption')
    const loginDao = require('../dao/loginDao')

    passport.use(new localStrategy(
        {
            usernameField: 'username',
            passwordField: 'password'
        },
        async function(phone, password, done) {
            password = await encryption.getMd5Pass(password)
            let result = await loginDao.checkLogin(phone, password)
            if(result) {
                return done(null, result, '登陆成功')
            }
            else {
                return done(null, false, '账号密码错误')
            }
        }
    ))

    passport.serializeUser(function(user, done) {
        console.log('user_ps:' + user)
        done(null, user)
    })

    passport.deserializeUser(function(user, done) {
        done(null, user)
    })

    module.exports = passport